<template>
    
  <view class="login-container tn-main-gradient-orangeyellow">
    <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar>

    <view class="login-box">
      <view class="title">
        <image class="logo-image" src="/static/84a24bb8b4854c633e85ee15c18737b1.png" mode="aspectFit"></image>
      </view>
      
      <!-- 添加温馨文字 -->
      <view class="slogan">每个宝贝都应被温柔以待</view>
      
      <view class="input-group">
        <input 
          class="input" 
          type="text" 
          v-model="formData.username" 
          placeholder="请输入用户名"
        />
      </view>
      
      <view class="input-group">
        <input 
          class="input" 
          type="password" 
          v-model="formData.password" 
          placeholder="请输入密码"
        />
      </view>
      
      <button class="login-btn" style="background-color: #080808;" @tap="handleLogin">登录</button>
      
      <!-- <view class="options">
        <text @tap="toRegister">注册账号</text>
        <text @tap="toForgetPassword">忘记密码</text>
      </view> -->
    </view>
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
  import { userLogin } from '@/api/user.js'
export default {
  mixins: [template_page_mixin],
  data() {
    return {
      formData: {
        username: '',
        password: ''
      }
    }
  },
  
  methods: {
    async handleLogin() {
      if (!this.formData.username || !this.formData.password) {
        uni.showToast({
          title: '请输入用户名和密码',
          icon: 'none'
        })
        return
      }

      try { 
        const res = await userLogin(this.formData)
        console.log("login res", res)
          uni.setStorageSync('USER_TOKEN', res.access_token)
          uni.setStorageSync('USER_INFO', res)
          uni.navigateTo({
          url: '/pages/index/index'
          })
      } catch (error) {
        uni.showToast({
          title: error.message,
          icon: 'none'
        })
        console.error('Error updating list data:', error);
      }
  
    },
    
    toRegister() {
      uni.navigateTo({
        url: '/pages/register/register'
      })
    },
    
    toForgetPassword() {
      uni.navigateTo({
        url: '/pages/forget-password/forget-password'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '@/static/css/templatePage/custom_nav_bar.scss';
.login-container {
  min-height: 100vh;
  background-color: #fff;
  padding: 40rpx;
  
  .login-box {
    margin-top: 120rpx;
    padding: 40rpx;
    
    .title {
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 auto;
      margin-bottom: 80rpx;
      border-radius: 20rpx;
      width: 140rpx;
      height: 140rpx;
      background-color: #fff;
      box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); // 添加阴影效果
      
      .logo-image {
        width: 110rpx;
        height: 110rpx;
      }
    }
      .slogan {
      text-align: center;
      font-size: 38rpx;
      color: #222222;
      margin-bottom: 70rpx;
      font-weight: 600;
      letter-spacing: 4rpx;
      line-height: 1.4;
      position: relative;
      padding: 0 20rpx;
      font-family: "草书", "草体", "草书体", "华文草书", "STCaiyun", serif;
      
      &::after {
        content: "";
        position: absolute;
        bottom: -16rpx;
        left: 50%;
        transform: translateX(-50%);
        width: 100rpx;
        height: 3rpx;
        background-color: #333;
        opacity: 0.2;
        border-radius: 3rpx;
      }
    }
    
    .input-group {
      margin-bottom: 40rpx;
      
      .input {
        color: #000;
        width: 100%;
        height: 100rpx;
        background-color: #FAFAFA;
        border-radius: 16rpx;
        padding: 0 40rpx;
        font-size: 30rpx;
        box-sizing: border-box;
        border: 2rpx solid #EAEAEA;
        
        &:focus {
          border-color: #FF8C00;
        }
      }
    }
    
    .login-btn {
      width: 100%;
      height: 100rpx;
      color: #fff;
      border-radius: 16rpx;
      font-size: 32rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 80rpx 0;
      font-weight: 500;
      transition: all 0.3s ease;
      
      &:active {
        background-color: #FF7400;
      }
    }
    
    .options {
      display: flex;
      justify-content: space-between;
      font-size: 28rpx;
      color: #999;
      padding: 0 20rpx;
      
      text {
        color: #FF8C00;
        transition: all 0.3s ease;
        
        &:active {
          color: #FF7400;
        }
      }
    }
  }
}
</style>